#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define y1 y_alpha_1

using namespace std;

using ll = long long;
using db = double;
using vec = vector<int>;
using pii = pair<int,int>;

ll read() {
	ll x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-',ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
	return f ? -x : x;
}

const int N = 3e5 + 10;

int n,m,f[N],a[N],c[N],ans2[N],ans1[N],dep[N];
vec G[N];
ll h[N],v[N];

namespace Heap {
	int ch[N][2],dis[N],rt[N];
	ll mul[N],val[N],add[N];
	void Mul(int o,ll v) { mul[o] *= v, val[o] *= v , add[o] *= v; }
	void Add(int o,ll v) { val[o] += v; add[o] += v; }
	void pushdn(int o) { if(mul[o] != 1) Mul(ch[o][0],mul[o]),Mul(ch[o][1],mul[o]),mul[o] = 1; if(add[o]) Add(ch[o][0],add[o]),Add(ch[o][1],add[o]),add[o] = 0; }
	int merge(int x,int y) {
		if(!x || !y) return x | y;
		if(val[x] > val[y]) swap(x,y); pushdn(x); pushdn(y); ch[x][1] = merge(ch[x][1],y); if(dis[ch[x][1]] > dis[ch[x][0]]) swap(ch[x][0],ch[x][1]);
		dis[x] = dis[ch[x][1]] + 1; return x;
	}
}

void dfs(int x) {
	for(auto y : G[x]) dep[y] = dep[x] + 1, dfs(y), Heap :: rt[x] = Heap :: merge(Heap :: rt[x],Heap :: rt[y]);
	while(Heap :: rt[x] && Heap :: val[Heap :: rt[x]] < h[x]) 
		Heap :: pushdn(Heap :: rt[x]), ans2[Heap :: rt[x]] = dep[c[Heap :: rt[x]]] - dep[x], ans1[x]++, Heap :: rt[x] = Heap :: merge(Heap :: ch[Heap :: rt[x]][0],Heap :: ch[Heap :: rt[x]][1]);
	if(a[x] == 0) Heap :: Add(Heap :: rt[x],v[x]); else Heap :: Mul(Heap :: rt[x],v[x]);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in; for(int i = 1;i <= n;i++) h[i] = in;
	for(int i = 2;i <= n;i++) f[i] = in,a[i] = in,v[i] = in,G[f[i]].pb(i);
	for(int i = 1;i <= m;i++) Heap :: val[i] = in, Heap :: add[i] = 0, Heap :: mul[i] = 1, c[i] = in, Heap :: rt[c[i]] = Heap :: merge(Heap :: rt[c[i]],i);
	dep[1] = 1; dfs(1);
	while(Heap :: rt[1]) Heap :: pushdn(Heap :: rt[1]),ans2[Heap :: rt[1]] = dep[c[Heap :: rt[1]]],Heap :: rt[1] = Heap :: merge(Heap :: ch[Heap :: rt[1]][0],Heap :: ch[Heap :: rt[1]][1]);
	for(int i = 1;i <= n;i++) printf("%d\n",ans1[i]);
	for(int i = 1;i <= m;i++) printf("%d\n",ans2[i]);
	return 0;
}
